# 设置项目名和版本
cmake_minimum_required(VERSION 3.15)
project(vofa_frame VERSION 1.0.0 LANGUAGES CXX)

# 设置库输出目录
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# 添加头文件搜索路径
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)

# 添加库源文件
add_library(vofa_frame SHARED src/vofa_frame.cpp)
target_include_directories(vofa_frame PUBLIC
		$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
        $<INSTALL_INTERFACE:include>
		PRIVATE /usr/local/include/eigen3
)

# 安装头文件
install(DIRECTORY include/vofa_frame
        DESTINATION include)

# 安装库文件
install(TARGETS vofa_frame
        EXPORT vofa_frameTargets
        ARCHIVE DESTINATION lib
        LIBRARY DESTINATION lib
        RUNTIME DESTINATION bin)

# 安装CMake配置文件
install(EXPORT vofa_frameTargets
        FILE vofa_frameTargets.cmake
        NAMESPACE ""
        DESTINATION lib/cmake/vofa_frame)

include(CMakePackageConfigHelpers)
configure_package_config_file(
        cmake/cmake_install.cmake.in
        ${CMAKE_CURRENT_BINARY_DIR}/vofa_frameConfig.cmake
        INSTALL_DESTINATION lib/cmake/vofa_frame
)
write_basic_package_version_file(
        ${CMAKE_CURRENT_BINARY_DIR}/vofa_frameConfigVersion.cmake
        VERSION ${PROJECT_VERSION}
        COMPATIBILITY AnyNewerVersion
)
install(FILES
        ${CMAKE_CURRENT_BINARY_DIR}/vofa_frameConfig.cmake
        ${CMAKE_CURRENT_BINARY_DIR}/vofa_frameConfigVersion.cmake
        DESTINATION lib/cmake/vofa_frame
        )

# uninstall目标
if (NOT TARGET uninstall)
    configure_file(
            cmake/cmake_uninstall.cmake.in
            ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
            IMMEDIATE @ONLY)
    add_custom_target(uninstall
            COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif ()
